<template>
  <div>
    <Header/>

    <div id="main">
      <article style="padding-top: 20px;">
        <div class="lbox">
          <div class="content_box whitebg">
            <h2 class="htitle">
              <span class="con_nav">
                您现在的位置是：<router-link to="/">网站首页</router-link>&gt;<span>留言反馈</span>
              </span>留言反馈
            </h2>

            <div class="con_text">
              <el-form ref="form" :model="form" :rules="rules" size="small">
                <el-form-item label="留言内容" prop="content">
                  <el-input v-model="form.content" type="textarea" :rows="5" placeholder="请输入内容" />
                </el-form-item>
                <el-form-item size="large">
                  <el-button type="primary" size="small" @click="submitForm">
                    确 定
                  </el-button>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>

        <Right/>
      </article>
    </div>

    <Footer/>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { addLeaves } from '@/api/leaves'
  import Header from '../common/Header.vue'
  import Footer from '../common/Footer.vue'
  import Right from '../common/Right.vue'

  export default {
    components: {
      Header,
      Footer,
      Right,
    },
    computed: {
      ...mapGetters([
        'userId',
      ])
    },
    data() {
      const validateData = (rule, value, callback) => {
        if (value == null || value.length == 0) {
          callback(new Error('必填项不能为空'));
        } else {
          callback();
        }
      }
      return {
        form: {},
        rules: {
          content: [{ required: true, trigger: 'blur', validator: validateData }],
        }
      }
    },
    methods: {
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.form.userId = this.userId
            addLeaves(this.form).then(response => {
              this.form = {}
              this.$message.success('提交成功');
            })
          }
        });
      },
    }
  }
</script>
